﻿using System.Security.Cryptography;
using System.Text;

namespace FlyingHat.Common.Helper
{
    public static class EncryptHelper
    {
        public static string Get32Md5(string strContent)
        {
            using MD5 md5 = MD5.Create();
            byte[] fromData = Encoding.UTF8.GetBytes(strContent);
            byte[] targetData = md5.ComputeHash(fromData);
            var sb = new StringBuilder();
            foreach (var item in targetData)
            {
                sb.Append(item.ToString("X2"));
            }
            return sb.ToString();
        }
        public static string GetPassword(string password, string salt)
        {
            return Get32Md5(password + salt);
        }
        public static string GetSalt()
        {
            var by = RandomNumberGenerator.GetBytes(36);
            var sb = new StringBuilder();
            foreach (var item in by)
            {
                sb.Append(item.ToString("X2"));
            }
            return sb.ToString();
        }
    }
}
